package com.example.demo.pattern.observer;

import com.example.demo.pattern.state.OrderState;
import com.example.demo.pattern.state.StateContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: demo
 * @description: 事件发布
 * @author: yby
 * @create: 2020-06-22 17:53
 **/
@RestController
@RequestMapping("/observer")
public class TestObserver {

    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping("/test/{publish}")
    public void test(@PathVariable("publish") String publish){
        System.out.println("开始发布事件...");
        MyEvent MyEvent = new MyEvent(publish);
        applicationContext.publishEvent(MyEvent);
        System.out.println("执行完毕。。。");
    }
}
